package cn.zb.common.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一JSON返回类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;
    private String msg;
    private T data;

    public static <T> Result<T> ok(){
        return new Result(200,"success",null);
    }
    public static <T> Result<T> ok(String msg){
        return new Result(200,msg,null);
    }
    public static <T> Result<T> ok(String msg,T data){
        return new Result(200,msg,data);
    }
    public static <T> Result<T> data(T data){
        return new Result(200,"success",data);
    }
    public static Result fail(String msg){
        return new Result(500,msg,null);
    }

    public static Result fail(int code,String msg){
        return new Result(code,msg,null);
    }
}
